﻿using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YellowMap.Resources;

namespace YellowMap
{
    public class FavoriteViewModel: BaseViewModel
    {
        List<Favorite> _favorites;
        public List<Favorite> Favorites
        {
            get
            {
                return _favorites;
            }

            set
            {
                _favorites = value;
                NotifyPropertyChanged("Favorites");
            }
        }

        public async Task Update(string cateId = "")
        {
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection(Constant.DB_NAME);

            var allTable = await conn.Table<Favorite>().ToListAsync();

            var list = await conn.Table<Favorite>().Where(h => h.SubCate.Contains(cateId)).ToListAsync();
            foreach (var item in list)
            {
                if (AppViewModel.Instance.SettingVM.Language == "Vi")
                {
                    item.View = LangVi.str_view;
                    item.Search = LangVi.str_search;
                    item.Delete = LangVi.str_delete;
                }
                else
                {
                    item.View = LangEn.str_view;
                    item.Search = LangEn.str_search;
                    item.Delete = LangEn.str_delete;
                }
            }
            Favorites = list;
        }
    }
}
